package com.wclass.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.wclass.entity.CourseChapter;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

/**
 * <p>
 * 章节 Mapper 接口
 * </p>
 *
 * @author 张浩高
 * @since 2018-12-20
 */
public interface CourseChapterMapper extends BaseMapper<CourseChapter> {

    /**
     * <p>
     * 根据 entity 条件，查询全部记录（并翻页）
     * </p>
     *
     * @param rowBounds 分页查询条件（可以为 RowBounds.DEFAULT）
     * @param wrapper   实体对象封装操作类（可以为 null）
     * @return List<T>
     */
    @Override
    @Select("select info.*,courseInfo.name as course_name,courseInfo.cover_img_url ${ew.sqlSelect} from " +
            "course_chapter as info left join course_info as courseInfo on info.course_info_id=courseInfo.id where " +
            "info.state=0 and courseInfo.audit_state=1 and courseInfo.state=0  ${ew.sqlSegment}")
    List<CourseChapter> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<CourseChapter> wrapper);

    @Override
    @Select("SELECT distinct info.* from course_chapter as info " +
            "left join coures_order as orderinfo on orderinfo.course_info_id = info.course_info_id " +
            "where info.state=0 ${ew.sqlSegment}")
    List<CourseChapter> selectList(@Param("ew") Wrapper<CourseChapter> wrapper);
}
